| Conditions | 17 |
| Total Lines | 80 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like UnknownFilePlugin.js ➔ UnknownFilePlugin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /** |
||
| 5 | function UnknownFilePlugin() { |
||
| 6 | "use strict"; |
||
| 7 | |||
| 8 | var divElement = undefined, |
||
|
|
|||
| 9 | self = this; |
||
| 10 | |||
| 11 | function initCSS() { |
||
| 12 | } |
||
| 13 | |||
| 14 | function initButtons() { |
||
| 15 | var leftToolbar = document.getElementById('toolbarLeft'); |
||
| 16 | // hide unused elements |
||
| 17 | document.getElementById("navButtons").style.display = 'none'; |
||
| 18 | document.getElementById("pageNumberLabel").style.display = 'none'; |
||
| 19 | document.getElementById("pageNumber").style.display = 'none'; |
||
| 20 | document.getElementById("numPages").style.display = 'none'; |
||
| 21 | document.getElementById("toolbar").style.display = 'none'; |
||
| 22 | document.getElementById("titlebarRight").style.display = 'none'; |
||
| 23 | leftToolbar.style.visibility = "visible"; |
||
| 24 | |||
| 25 | } |
||
| 26 | |||
| 27 | this.initialize = function ( viewerElement, documentUrl ) { |
||
| 28 | divElement = document.createElement("div"); |
||
| 29 | divElement.setAttribute('class', 'unknown-file'); |
||
| 30 | divElement.innerHTML = 'This file cannot be previewed using your browser. <br><br><a class="download-button" href="' + documentUrl + '">Click here to download</a>'; |
||
| 31 | |||
| 32 | viewerElement.appendChild(divElement); |
||
| 33 | viewerElement.style.overflow = "auto"; |
||
| 34 | |||
| 35 | self.onLoad(); |
||
| 36 | |||
| 37 | initCSS(); |
||
| 38 | initButtons(); |
||
| 39 | }; |
||
| 40 | |||
| 41 | this.isSlideshow = function () { |
||
| 42 | return false; |
||
| 43 | }; |
||
| 44 | |||
| 45 | this.onLoad = function () { |
||
| 46 | }; |
||
| 47 | |||
| 48 | this.fitToWidth = function ( width ) { |
||
| 49 | }; |
||
| 50 | |||
| 51 | this.fitToHeight = function ( height ) { |
||
| 52 | }; |
||
| 53 | |||
| 54 | this.fitToPage = function ( width, height ) { |
||
| 55 | }; |
||
| 56 | |||
| 57 | this.fitSmart = function ( width ) { |
||
| 58 | }; |
||
| 59 | |||
| 60 | this.getZoomLevel = function () { |
||
| 61 | }; |
||
| 62 | |||
| 63 | this.setZoomLevel = function ( value ) { |
||
| 64 | }; |
||
| 65 | |||
| 66 | this.getPages = function () { |
||
| 67 | return [1]; |
||
| 68 | }; |
||
| 69 | |||
| 70 | this.showPage = function ( n ) { |
||
| 71 | }; |
||
| 72 | |||
| 73 | this.getPluginName = function () { |
||
| 74 | return "UnknownFilePlugin"; |
||
| 75 | }; |
||
| 76 | |||
| 77 | this.getPluginVersion = function () { |
||
| 78 | return "From Source"; |
||
| 79 | }; |
||
| 80 | |||
| 81 | this.getPluginURL = function () { |
||
| 82 | return "https://grommunio.com"; |
||
| 83 | }; |
||
| 84 | } |
||
| 85 |